package com.lh;

import com.lh.model.Student;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.ImportResource;
import org.springframework.context.annotation.PropertySource;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.transaction.annotation.EnableTransactionManagement;

/**
 * @Author: LuoHang
 *
 * classpath：表示的意思是在target/classes类路径的位置
 *
 * 注解：
 *   1.@MapperScan(basePackages = {"com.lh.dao"}) 开启Dao层扫描（DAO层类就无需使用@Mapper注解）
 *   2.@EnableAsync 导入自动配置异步组件
 *   3.@ServletComponentScan(basePackages = {"com.lh.servlet"}) 开启Servlet包扫描
 *   4.@EnableTransactionManagement 开启事务管理，支持事务；启注解事务管理，等同于xml配置方式的 <tx:annotation-driven />
 *   5.@PropertySource 相当于<context:property-placeholder location="classpath:config.properties"/>
 *   6.@ImportResource 相当于<import resource="classpath:bean.xml"/>
 */
@SpringBootApplication
@MapperScan(basePackages = {"com.lh.dao"})
@EnableAsync
@ServletComponentScan(basePackages = {"com.lh.servlet","com.lh.filter","com.lh.listener"})
@EnableTransactionManagement
@PropertySource(value = {"classpath:student.properties"})
@ImportResource(value = {"classpath:bean.xml"})
public class Springboot002AsyncApplication {
	public static void main(String[] args) {

		SpringApplication application = new SpringApplication(Springboot002AsyncApplication.class);
		application.setBannerMode(Banner.Mode.CONSOLE);
		ApplicationContext context = application.run(args);
		//ApplicationContext context = SpringApplication.run(Springboot002AsyncApplication.class, args)

		//MyAopService service = (MyAopService) context.getBean("myAopServiceImpl")
		//System.out.println(service.getPojo())
		//将student的属性值以student.properties形式导入，使用@ConfigurationProperties，将properties中的值赋值给对象属性
		Student student = (Student) context.getBean("student");
		System.out.println("@Component+@ConfigurationProperties:student对象：" + student);
		Student studentByXml = (Student) context.getBean("studentByXml");
		System.out.println("bean.xml导入的对象：" + studentByXml);
	}
}
